package com.supreme.studyserver.controller;

import com.supreme.commonboot.utils.AjaxResp;
import com.supreme.studyserver.service.MallService;
import com.supreme.studyserver.service.mall.EnumMallType;
import com.supreme.studyserver.service.mall.SuperMallService;
import com.supreme.studyserver.strategy.Singleton;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "design-patten")
public class DesignPattenController {

    @Resource
    private SuperMallService superMallService;

    @GetMapping(value = "enum/{type}")
    public AjaxResp testEnum(@PathVariable(value = "type") String type) {
        EnumMallType enumMallType = EnumMallType.findByValue(type);
        return AjaxResp.instance(enumMallType);
    }

    @GetMapping(value = "singleton")
    public AjaxResp singleton() {
        Singleton instance = Singleton.getInstance();
        return AjaxResp.instance(instance.getTitle());
    }

    @GetMapping(value = "spring-strategy/{mallType}")
    public AjaxResp springStrategy(@PathVariable(value = "mallType") String mallType) {
        MallService mallService = superMallService.getMallService(mallType);
        mallService.showMallName();
        return AjaxResp.instance();
    }
}
